package com.platform.comm.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.platform.comm.constants.GlobalConstant;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * Description: Base-DTO
 *
 * @author libin Created on 2019/7/16
 **/
@Getter
@Setter
public class BaseQo extends AbstractQo {

    private static final long serialVersionUID = 7591744352499631572L;

    @JsonFormat(pattern = GlobalConstant.DATE_TIME_PATTERN, shape = JsonFormat.Shape.STRING)
    @DateTimeFormat(pattern = GlobalConstant.DATE_TIME_PATTERN)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createDate;

    @JsonFormat(pattern = GlobalConstant.DATE_TIME_PATTERN, shape = JsonFormat.Shape.STRING)
    @DateTimeFormat(pattern = GlobalConstant.DATE_TIME_PATTERN)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime updateDate;

    /**
     * 初始化数据
     */
    @Override
    public void init() {
        this.setCreateDate(LocalDateTime.now());
        this.setUpdateDate(LocalDateTime.now());
    }
}
